﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using BusinessFacade;
using EntityManage;

public partial class Modules_Personal_MyNoticeDetail : System.Web.UI.Page
{
    IOther_NoticeHandler noticeHandler = new Other_NoticeManage();
    IOther_NoticeAttachHandler noticeAttHandler = new Other_NoticeAttachManage();
    ISys_UserHandler userHandler = new Sys_UserManage();

    ISys_UserHandlerExt userHandlerExt = new Sys_UserManageExt();
    IPerf_Personal_EvaluateHandlerExt evaluateHandlerExt = new Perf_Personal_EvaluateManageExt();
    IPerf_Personal_FinalAssignHandler finalAssignHandler = new Perf_Personal_FinalAssignManage();
    DataBase db = new DataBase();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dataBind();
            dataBindTarget();
        }
    }

    public string GetUserName(object id)
    {
        return userHandlerExt.GetUserNameByID(int.Parse(id.ToString()));
    }

    public void dataBindTarget()
    {
        if (Request["ID"] != null)
        {
            Other_NoticeQuery q = noticeHandler.GetOther_NoticeQuery(int.Parse(Request["ID"]));
            if (q != null)
            {

                string sqlStr = @"select t.Name,edtl.Score,edtl.Evaluate_ID, edtl.User_ID,edtl.ID,edtl.Target_ID,edtl.InsertTime,edtl.Remark
from Perf_Personal_EvaluateDtl edtl 
inner join Perf_Personal_Target t on t.ID=edtl.Target_ID where  Evaluate_ID in(select EvaluateIDs from Perf_Personal_Approval where ID=@BusinessID)";

                DataTable dtCount = db.RunSqlTab(sqlStr, new SqlParameter[] { new SqlParameter("@BusinessID", q.Business_ID) });

                DataTable dt = db.GetDataTableByIndex(sqlStr, new SqlParameter[] { new SqlParameter("@BusinessID", q.Business_ID) }, AspNetPager.StartRecordIndex - 1, AspNetPager.PageSize);

                if (dtCount != null && dtCount.Rows.Count > 0)
                {
                    AspNetPager.RecordCount = dtCount.Rows.Count;
                }
                gvTargetEvalate.DataSource = dt;
                gvTargetEvalate.DataBind();
            }
        }
    }

    protected void AspNetPager_PageChanged(object src, EventArgs e)
    {

        dataBindTarget();
    }
    

    private void dataBind()
    {
        if (Request["ID"] != null && Request["ID"] != string.Empty)
        {
            int ID = 0;
            int.TryParse(Request["ID"], out ID);

            if (ID != 0)
            {
                try
                {
                    Other_NoticeQuery noticeQuery = noticeHandler.GetOther_NoticeQuery(ID);
                    if (noticeQuery != null)
                    {
                        Sys_UserQuery userQuery = userHandler.GetSys_UserQuery(noticeQuery.User_ID);
                        lblUser.Text = userQuery.Name;
                        lblTitle.Text = noticeQuery.Title;
                        lblDate.Text = noticeQuery.Create_Date.ToString();
                        lblContent.InnerHtml = noticeQuery.Content;

                        Other_NoticeAttachQuery[] attList = noticeAttHandler.GetOther_NoticeAttachQueryList(" Notice_ID = @Notice_ID", new SqlParameter[] { new SqlParameter("@Notice_ID", ID) });
                        StringBuilder sb = new StringBuilder();
                        if (attList != null && attList.Length > 0)
                        {
                            foreach (Other_NoticeAttachQuery attQuery in attList)
                            {
                                sb.Append("<a href=\"?method=download&aid=" + attQuery.ID.ToString() + "\">");
                                sb.Append(attQuery.Name);
                                sb.Append("</a><br/>");
                            }

                            spnAttachList.InnerHtml = sb.ToString();
                        }
                    }
                }
                catch
                {
                    Jscript.Alert("操作失败!", this.Page);
                }
            }
        }
    }

}
